<?php
declare(strict_types=1);

namespace app\command;

use app\model\ExpressPriceCache;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Log;

class ClearExpressCache extends Command
{
    protected function configure()
    {
        $this->setName('clear:express-cache')
            ->setDescription('Clear expired express price cache');
    }

    protected function execute(Input $input, Output $output)
    {
        try {
            $days = env('EXPRESS_CACHE_EXPIRE_DAYS', 7);
            
            // 清理过期缓存
            $count = ExpressPriceCache::clearExpired($days);
            
            $output->writeln("Successfully cleared {$count} expired express price cache records");
            Log::info("清理过期快递价格缓存成功: {$count} 条记录");

        } catch (\Exception $e) {
            $output->writeln("<error>Failed to clear express price cache: {$e->getMessage()}</error>");
            Log::error("清理过期快递价格缓存失败: " . $e->getMessage());
        }
    }
} 